<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta charset="UTF-8">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=0"/>
    <meta content="yes" name="apple-Mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <!--Use for debugging must be removed under production -->
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" CONTENT="no-cache">
    <meta http-equiv="Pragma" CONTENT="no-cache">
    <!-->
    <title>拍书献爱心#宁波印象城・蔡康永的秘密书房展</title>
</head>
<body style="display:block">
<div class="cc" style="height:100%"></div>
<button id='photo' style="opacity:0">Photo</button>
</body>
<script src="./js/common.js"></script>
<script>
    (function () {
        var $body = document.querySelector('body');
        $body.addEventListener('touchstart', function (e) {
            e.preventDefault();
        }, false);
        var script = document.createElement('script');
        script.src = './js/entry.js?t=' + (+new Date());
        $body.appendChild(script);
        var $head = document.querySelector('head');
        var link = document.createElement('link');
        link.rel = 'stylesheet';
        link.href = 'css/main/preHeat.css?t=' + (+new Date());
        $head.appendChild(link);
    })();

</script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
    var getPar = function (par) {
        var regex = new RegExp('[?&]' + par + '=([^&]*)', 'i');
        var tmpStr = decodeURI(window.location.href);
        var result = tmpStr.match(regex);
        return result= result ? result[1] : result;
    }
    var openid = getPar('openid') ? getPar('openid') : "no";
    var name = getPar('nickname') ? getPar('nickname') : "no";
    if(getPar('wa')){
        openid=+new Date();
        name='watcher';
    }
    if ('no' == openid && 'no' == name) {

        window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx2a1af4283cc7575e&redirect_uri=http://query.viscovery.net.cn/wechat/wechat_userinfo.php?url=http://query.viscovery.net.cn/preHeat/preHeat.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
    }
    var url = window.location.href;
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var config = JSON.parse(xhr.responseText);
            var tl='http://query.viscovery.net.cn/preHeat/preHeat.html';
            var sharedData = {
                desc: '拍书献爱心#宁波印象城・蔡康永的秘密书房展',
                link: tl,
                imgUrl: 'http://query.viscovery.net.cn/preHeat/res/img/cky.jpg'
            };
            wx.config({
      /*          debug:true,*/
                appId: config["appId"],
                timestamp: config["timestamp"],
                nonceStr: config["nonceStr"],
                signature: config["signature"],
                jsApiList: [
                    'uploadImage', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'chooseImage'
                ]
            });
            wx.ready(function () {
                wx.onMenuShareAppMessage({
                    title: sharedData.title,
                    desc: sharedData.desc,
                    link: sharedData.link,
                    imgUrl: sharedData.imgUrl
                });
                wx.onMenuShareTimeline({
                    title: sharedData.title,
                    desc: sharedData.desc,
                    link: sharedData.link,
                    imgUrl: sharedData.imgUrl
                });
            })

        }

    }
    xhr.open('get', '../wechat/wxconfig.php?' + url, true);
    xhr.send();
    document.querySelector("#photo").onclick = function () {
        console.log('selector');
        wx.chooseImage({
            count: 1,
            success: function (res) {
                var mylocalId = res.localIds[0]; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                wx.uploadImage({
                    localId: mylocalId, // 需要上传的图片的本地ID，由chooseImage接口获得
                    isShowProgressTips: 0, // 默认为1，显示进度提示
                    success: function (res) {
                        var serverId = res.serverId; // 返回图片的服务器端ID
                        window.location.href = '../wechat/booksphoto/index.html?openid=' + openid + '&localid=' + mylocalId + '&serverid=' + serverId + '&name=' + name;
                    }
                });

            }
        });
    };
</script>
</html>